package com.ly.algorithm.leetcode.tree;

/**
 * @Classname Problem101
 * @Description
 *
 * 例如，二叉树 [1,2,2,3,4,4,3] 是对称的。
 *
 *     1
 *    / \
 *   2   2
 *  / \ / \
 * 3  4 4  3
 *  
 *
 * 但是下面这个 [1,2,2,null,3,null,3] 则不是镜像对称的:
 *
 *     1
 *    / \
 *   2   2
 *    \   \
 *    3    3
 *
 * @Date 2020/12/22 20:17
 * @Author 冷心影翼
 */
public class Problem101 {

	public static void main(String[] args) {
		Solution101 solution101 = new Solution101();
		TreeNode treeNode = new TreeNode(1);
		treeNode.left = new TreeNode(2);
		treeNode.left.right = new TreeNode(3);
		treeNode.right = new TreeNode(2);
		treeNode.right.right = new TreeNode(3);
		System.out.println(solution101.isSymmetric(treeNode));
	}

}


class Solution101 {
	public boolean isSymmetric(TreeNode root) {
		if(root == null)
			return true;
		return isSymmetric(root.left,root.right);
	}

	public boolean isSymmetric(TreeNode node1,TreeNode node2) {
		if(node1 == null && node2 == null)
			return true;
		if(node1 == null  || node2==null || (node1.val != node2.val))
			return false;
		return isSymmetric(node1.left,node2.right) && isSymmetric(node1.right,node2.left);
	}
}